package com.ruoyi.system.controller;

import com.ruoyi.system.domain.HotelBook;
import com.ruoyi.system.service.IHotelBookService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 酒店预订Controller
 * 
 * @author xdh
 * @date 2024-06-25
 */
@RestController
@RequestMapping("/booking/book")
public class HotelBookController extends BaseController
{
    @Autowired
    private IHotelBookService hotelBookService;

    /**
     * 查询酒店预订列表
     */
    @PreAuthorize("@ss.hasPermi('booking:book:list')")
    @GetMapping("/list")
    public TableDataInfo list(HotelBook hotelBook)
    {
        startPage();
        List<HotelBook> list = hotelBookService.selectHotelBookList(hotelBook);
        return getDataTable(list);
    }

    /**
     * 导出酒店预订列表
     */
    @PreAuthorize("@ss.hasPermi('booking:book:export')")
    @Log(title = "酒店预订", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HotelBook hotelBook)
    {
        List<HotelBook> list = hotelBookService.selectHotelBookList(hotelBook);
        ExcelUtil<HotelBook> util = new ExcelUtil<HotelBook>(HotelBook.class);
        util.exportExcel(response, list, "酒店预订数据");
    }

    /**
     * 获取酒店预订详细信息
     */
    @PreAuthorize("@ss.hasPermi('booking:book:query')")
    @GetMapping(value = "/{bookingId}")
    public AjaxResult getInfo(@PathVariable("bookingId") Integer bookingId)
    {
        return success(hotelBookService.selectHotelBookByBookingId(bookingId));
    }

    /**
     * 新增酒店预订
     */
    @PreAuthorize("@ss.hasPermi('booking:book:add')")
    @Log(title = "酒店预订", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HotelBook hotelBook)
    {
        return toAjax(hotelBookService.insertHotelBook(hotelBook));
    }

    /**
     * 修改酒店预订
     */
    @PreAuthorize("@ss.hasPermi('booking:book:edit')")
    @Log(title = "酒店预订", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HotelBook hotelBook)
    {
        return toAjax(hotelBookService.updateHotelBook(hotelBook));
    }

    /**
     * 删除酒店预订
     */
    @PreAuthorize("@ss.hasPermi('booking:book:remove')")
    @Log(title = "酒店预订", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bookingIds}")
    public AjaxResult remove(@PathVariable Integer[] bookingIds)
    {
        return toAjax(hotelBookService.deleteHotelBookByBookingIds(bookingIds));
    }
}
